<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的财务</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f9f9f9;
            padding: 20px;
        }
        .container {
            max-width: 800px;
            margin: auto;
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        h2 {
            text-align: center;
        }
        .date-selector {
            display: flex;
            justify-content: space-between;
            margin-bottom: 20px;
        }
        .date-selector select {
            padding: 8px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            padding: 10px;
            text-align: left;
            border-bottom: 1px solid #ccc;
        }
        th {
            background-color: #007bff;
            color: white;
        }
        tr:hover {
            background-color: #f1f1f1;
        }
        .total {
            margin-top: 20px;
            font-size: 1.2em;
            text-align: center;
        }
    </style>
</head>
<body>

<div class="container">
    <h2>我的财务</h2>
    <div class="date-selector">
        <select id="dateFilter">
            <option value="today">今天</option>
            <option value="yesterday">昨天</option>
        </select>
        <button id="filterButton">查看</button>
    </div>
    <table>
        <thead>
            <tr>
                <th>订单号</th>
                <th>商品名称</th>
                <th>数量</th>
                <th>收入 (元)</th>
                <th>日期</th>
            </tr>
        </thead>
        <tbody id="finance-list">
            <tr>
                <td>1001</td>
                <td>商品A</td>
                <td>2</td>
                <td>200.00</td>
                <td>今天</td>
            </tr>
            <tr>
                <td>1002</td>
                <td>商品B</td>
                <td>1</td>
                <td>100.00</td>
                <td>今天</td>
            </tr>
        </tbody>
    </table>
    <div class="total" id="totalIncome">总收入: 300.00元</div>
</div>

<script>
    document.getElementById('filterButton').addEventListener('click', function() {
        const filterValue = document.getElementById('dateFilter').value;
        const financeList = document.getElementById('finance-list');
        const totalIncome = document.getElementById('totalIncome');

        // 示例数据（在真实应用中应从后端获取）
        const data = {
            today: [
                { orderId: '1001', productName: '商品A', quantity: 2, income: 200.00, date: '今天' },
                { orderId: '1002', productName: '商品B', quantity: 1, income: 100.00, date: '今天' },
            ],
            yesterday: [
                { orderId: '1003', productName: '商品C', quantity: 3, income: 300.00, date: '昨天' },
                { orderId: '1004', productName: '商品D', quantity: 1, income: 150.00, date: '昨天' },
            ]
        };

        // 清空现有数据
        financeList.innerHTML = '';

        // 添加新的数据
        let total = 0;
        data[filterValue].forEach(item => {
            const row = `<tr>
                <td>${item.orderId}</td>
                <td>${item.productName}</td>
                <td>${item.quantity}</td>
                <td>${item.income.toFixed(2)}</td>
                <td>${item.date}</td>
            </tr>`;
            financeList.innerHTML += row;
            total += item.income;
        });

        // 更新总收入
        totalIncome.innerText = `总收入: ${total.toFixed(2)}元`;
    });
</script>

</body>
</html>
